﻿using System.Collections.Generic;

using NUnit.Framework;
using NUnit.Framework.SyntaxHelpers;

using SharpArch.Core;
using SharpArch.Core.PersistenceSupport;
using SharpArch.Testing.NUnit;

using Quiziqal.Domain;

namespace Quiziqal.Specifications.Domain
{
    [TestFixture]
    public class when_creating_a_quiz : BehaviorSpecificationTestsBase
    {
        const string USERNAME = "username";
        User user;
        Quiz quiz;

        protected override void EstablishContext()
        {
            user = new User(USERNAME);
        }

        protected override void Act()
        {
            quiz = new Quiz(user);
        }

        [Test]
        public void owner_should_be_set_by_constructor_argument()
        {
            quiz.Owner.ShouldEqual(user);
        }
    }

    [TestFixture]
    public class when_creating_a_quiz_with_an_empty_constructor : BehaviorSpecificationTestsBase
    {
        Quiz quiz;

        protected override void EstablishContext() { }

        protected override void Act()
        {
            quiz = new Quiz();
        }

        [Test]
        public void should_not_be_valid()
        {
            quiz.IsValid().ShouldBeFalse();
        }
    }

    [TestFixture]
    public class when_creating_a_quiz_with_an_invalid_user : BehaviorSpecificationTestsBase
    {
        Quiz quiz;

        protected override void EstablishContext() { }

        protected override void Act()
        {
            quiz = new Quiz(null);
        }

        [Test]
        public void should_throw_precondition_exception()
        {
            ExceptionThrown.ShouldBeOfType(typeof(PreconditionException));
        }
    }
}
